package com.logistics.controller;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.logistics.compont.ResponseApi;
import com.logistics.entity.StatusEntity;
import com.logistics.pojo.Employee;
import com.logistics.service.LoginService;
import com.logistics.util.CodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/employee")
public class LoginController {

    @Autowired
    private LoginService loginService;

    //获取验证码
    @GetMapping("/getCode")
    public ResponseApi getCode(){
        String code = CodeUtil.generator(StatusEntity.CODE_SAR);
        return ResponseApi.SUCCESS(code);
    }

    @PostMapping("/login")
    public ResponseApi login(@RequestBody Employee employee){
        ResponseApi responseApi = loginService.login(employee);
        if(ObjectUtils.isEmpty(responseApi.getData())){
            return ResponseApi.FAILED("登录失败。");
        }
        return responseApi;
    }

    @GetMapping("/logout")
    public ResponseApi logout(){
        return loginService.loginOut();
    }


}
